﻿using UnityEngine;
using System.Collections;

public class shoot : MonoBehaviour {
    public GameObject obj;
    public GameObject paokou;
    GameObject pao;
    bool pao_instance = false;
         
	void Start () {
	
	}
	
	void Update () {
        RaycastHit hit;
        if (Input.GetButtonDown("Fire1"))
        {
            if (Physics.Raycast(paokou.transform.position, paokou.transform.forward, out hit, 30f))
            {
                if (hit.collider.tag == "enemy" && !pao_instance)
                {
                    pao = GameObject.Instantiate(obj);
                    pao.transform.position = paokou.transform.position;
                    pao.transform.rotation = paokou.transform.rotation;
                    pao_instance = true;
                    pao.transform.parent = paokou.transform;
                    pao.GetComponent<Rigidbody>().AddForce(paokou.transform.forward * 1000);
                    paokou.transform.DetachChildren();
                    pao_instance = false;
                    getPao.paoNum--;
                    print("炮弹：" + getPao.paoNum);
                }
            }
        }
        
	}
}
